﻿using System.Threading.Tasks;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using VOL.Core.Utilities;
using VOL.Domain.IServices.MasterData;
using VOL.Entity.DomainModels;

namespace VOL.WebApi.Controllers.MasterData
{
    [Route("api/[controller]/[action]")]
    [ApiController]
    public class MaterialProductController : ControllerBase
    {
        private readonly IMaterialProductService _materialProductService;

        public MaterialProductController(IMaterialProductService materialProductService)
        {
            _materialProductService = materialProductService;
        }

        /// <summary>
        /// 获取物料产品列表
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        public async Task<WebResponseContent> GetMaterialProduct(string materialCode, string materialName, int pageIndex, int pageSize)
        {
            return await _materialProductService.GetMaterialProduct(materialCode, materialName, pageIndex, pageSize);
        }

        /// <summary>
        /// 添加物料产品
        /// </summary>
        /// <param name="materialProduct">物料产品信息</param>
        /// <returns></returns>
        [HttpPost]
        public async Task<WebResponseContent> AddMaterialProduct([FromBody] MaterialProduct materialProduct)
        {
            return await _materialProductService.AddMaterialProduct(materialProduct);
        }

        /// <summary>
        /// 更新物料产品
        /// </summary>
        /// <param name="materialProduct">物料产品信息</param>
        /// <returns></returns>
        [HttpPost]
        public async Task<WebResponseContent> UpdateMaterialProduct([FromBody] MaterialProduct materialProduct)
        {
            return await _materialProductService.UpdateMaterialProduct(materialProduct);
        }

        /// <summary>
        /// 删除物料产品
        /// </summary>
        /// <param name="id">物料产品ID</param>
        /// <returns></returns>
        [HttpGet]
        public async Task<WebResponseContent> DeleteMaterialProduct([FromQuery]int id)
        {
            return await _materialProductService.DeleteMaterialProduct(id);
        }
    }
}
